/*
 * @(#)LoginAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework.web;

import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.Utility;
import com.dcivision.user.auth.AuthenticationHandler;
import com.dcivision.user.bean.UserRecord;

/**
  LoginAction.java

  This class is an action for login.

    @author          Scott Tong
    @company         DCIVision Limited
    @creation date   15/07/2003
    @version         $Revision: 1.3.2.2 $
*/

public class AuthenticateAction extends AbstractAction {

  public static final String REVISION = "$Revision: 1.3.2.2 $";
  protected static final String  WRONG_PASSWORD = "errors.login.wrong_password";
  protected AuthenticationHandler authHandler = null;

  /** Creates a new instance of MaintUserGroupAction */
  public AuthenticateAction() {
    super();
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    LoginForm loginForm = (LoginForm)form;
    SessionContainer sessionCtn = this.getSessionContainer(request);
    UserRecord userRecord = null;
    Connection conn = null;

    String loginPwd  = loginForm.getLoginPwd();
    String auditStatus = "";
    String userIP = request.getRemoteAddr();
    String forwardInfo = (String)request.getAttribute("AUTHENTICATE_FAILED");

    try {
      if (!Utility.isEmpty(forwardInfo)) {
        log.debug("request is Authenticate");
        //request.setAttribute("password", loginPwd);
        addError(request, WRONG_PASSWORD);
        return mapping.findForward("AUTHENTICATE");
      } 
    }catch (Exception ex) {
      log.error(ex, ex);
    }
    return mapping.findForward("AUTHENTICATE");
  }

  /* (non-Javadoc)
   * @see com.dcivision.framework.web.AbstractAction#getFunctionCode()
   */
  public String getFunctionCode() {
    
    return null;
  }

  /* (non-Javadoc)
   * @see com.dcivision.framework.web.AbstractAction#getMajorDAOClassName()
   */
  public String getMajorDAOClassName() {
    
    return null;
  }   
}
